package com.du.task02;

/**
 *  编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打印出来。
 */
public class CountStr {
    public static void main(String[] args) {
        String str="ABCD123!@#$%ab";
        int[] int1=new int[4];
        char[] cha=str.toCharArray();
        StringBuilder stb1=new StringBuilder();
        StringBuilder stb2=new StringBuilder();
        StringBuilder stb3=new StringBuilder();
        StringBuilder stb4=new StringBuilder();
        String res="^[A-Z]$";
        String res1="^[a-z]$";
        String res2="^\\d$";
        String res3="^[^a-zA-Z0-9]$";
        for(char a:cha){
            if(Character.valueOf(a).toString().matches(res)){
                int1[0]++;
                stb1.append(a);
            }
            else if(Character.valueOf(a).toString().matches(res1)){
                int1[1]++;
                stb2.append(a);
            }
            else if(Character.valueOf(a).toString().matches(res2)){
                int1[2]++;
                stb3.append(a);
            }else{
                int1[3]++;
                stb4.append(a);
            }

        }
        System.out.println("字符串中大写字母有"+int1[0]+"个"+",分别是"+stb1);
        System.out.println("字符串中小写字母有"+int1[1]+"个"+",分别是"+stb2);
        System.out.println("字符串中数字有"+int1[2]+"个"+",分别是"+stb3);
        System.out.println("字符串中其它字符有"+int1[3]+"个"+",分别是"+stb4);
    }
}
